package cn.scut.srp.controller.afterLogin.student;

import cn.scut.srp.model.BaseResponse;
import cn.scut.srp.model.ResponseCode;
import cn.scut.srp.service.StudentService;
import cn.scut.srp.utils.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student/reserve")
@Slf4j
public class StudentController {

    @Autowired
    private StudentService service;


    @GetMapping("/by_class")
    public BaseResponse<ResponseCode> getReserveByClass(@RequestHeader("Authorization") String token,
                                                 @RequestParam String className){
        //根据班级获取课程
        List<String> courseNames = service.getClassCourses(className);
        if(courseNames == null){
            return ResponseUtil.noCourse("没找到课程");
        }
        //再根据课程获取机房
        return service.getReserveByCourses(courseNames);
    }

    @GetMapping("/by_course")
    public BaseResponse<ResponseCode> getReserveByCourse(@RequestHeader("Authorization") String token,
                                                        @RequestParam String courseName){
        return service.getReserveByCourse(courseName);
    }

}
